import { Controller } from 'egg';

export default class TemplatePageController extends Controller {

  public async index() {
    const data = await this.ctx.service.templatePage.all();
    this.ctx.sendSuccess(data);
  }

  public async create() {
    const { w_validate_pagePath, w_validate_description, w_validate_otherName } = this.ctx
    this.ctx.validate({
      name: w_validate_otherName,
      path: w_validate_pagePath,
      description: w_validate_description,
    });
    await this.ctx.service.templatePage.create(this.ctx.w_body('name description path'));
    this.ctx.sendSuccess('OK');
  }

  public async update() {
    const { id } = this.ctx.params
    const { w_validate_pagePath, w_validate_description, w_validate_otherName } = this.ctx
    this.ctx.w_validate_param_id()
    this.ctx.validate({
      name: w_validate_otherName,
      path: w_validate_pagePath,
      description: w_validate_description,
    });
    await this.ctx.service.templatePage.update(id, this.ctx.w_body('name description path'));
    this.ctx.sendSuccess('OK');
  }

  public async remove() {
    const { id } = this.ctx.params
    this.ctx.w_validate_param_id()
    await this.ctx.service.templatePage.remove(id);
    this.ctx.sendSuccess('OK');
  }
  
}
